package com.jason.order.service;

import com.jason.order.feign.IAccountService;
import com.jason.order.feign.IProductService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class OrderBusService {
    @Autowired
    OrderTCCService orderTCCService;

    @Autowired
    IAccountService iAccountService;

    @Autowired
    IProductService iProductService;

    @GlobalTransactional
    @Transactional(rollbackFor = Exception.class)
    public void buyOrder(){
        int id = 1;
        int number = 1;
        orderTCCService.prepare(id,number);
        iAccountService.addAmount(id,number);
        iProductService.reduceNumberr(id,number);
        int j = 1;
        return;
    }
}
